using IrisGenerator.Common.Modules;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Modules
{
    
    
    public partial class ModuleParameterInstance {
        
        private System.Nullable<System.Guid> _modParInsId;
        
        private System.Nullable<System.Guid> _modInsId;
        
        private System.Nullable<System.Guid> _modParId;
        
        private System.Nullable<System.Guid> _modParInsValue;
        
        private ModuleInstance _moduleInstance;
        
        private ModuleParameter _moduleParameter;
        
        public virtual System.Nullable<System.Guid> ModParInsId {
            get {
                return _modParInsId;
            }
            set {
                _modParInsId = value;
            }
        }
        
        public virtual System.Nullable<System.Guid> ModParInsValue {
            get {
                return _modParInsValue;
            }
            set {
                _modParInsValue = value;
            }
        }
        
        public virtual ModuleInstance ModuleInstance {
            get {
                if ((this._moduleInstance == null)) {
                    this._moduleInstance = ModuleInstance.Load(this._modInsId);
                }
                return this._moduleInstance;
            }
            set {
                _moduleInstance = value;
            }
        }
        
        public virtual ModuleParameter ModuleParameter {
            get {
                if ((this._moduleParameter == null)) {
                    this._moduleParameter = ModuleParameter.Load(this._modParId);
                }
                return this._moduleParameter;
            }
            set {
                _moduleParameter = value;
            }
        }
        
        private void Clean() {
            this.ModParInsId = null;
            this._modInsId = null;
            this._modParId = null;
            this.ModParInsValue = null;
            this.ModuleInstance = null;
            this.ModuleParameter = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["MOD_PAR_INS_ID"] != System.DBNull.Value)) {
                this.ModParInsId = ((System.Nullable<System.Guid>)(dr["MOD_PAR_INS_ID"]));
            }
            if ((dr["MOD_INS_ID"] != System.DBNull.Value)) {
                this._modInsId = ((System.Nullable<System.Guid>)(dr["MOD_INS_ID"]));
            }
            if ((dr["MOD_PAR_ID"] != System.DBNull.Value)) {
                this._modParId = ((System.Nullable<System.Guid>)(dr["MOD_PAR_ID"]));
            }
            if ((dr["MOD_PAR_INS_VALUE"] != System.DBNull.Value)) {
                this.ModParInsValue = ((System.Nullable<System.Guid>)(dr["MOD_PAR_INS_VALUE"]));
            }
        }
        
        public static ModuleParameterInstanceCollection Select_MODULE_PARAMETER_INSTANCE_By_MOD_INS_ID(System.Nullable<System.Guid> MOD_INS_ID) {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                System.Data.DataSet ds = dbo.Select_MODULE_PARAMETER_INSTANCE_By_MOD_INS_ID(MOD_INS_ID);
                ModuleParameterInstanceCollection collection = new ModuleParameterInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleParameterInstance obj = new ModuleParameterInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleParameterInstanceCollection Select_MODULE_PARAMETER_INSTANCE_By_MOD_PAR_ID(System.Nullable<System.Guid> MOD_PAR_ID) {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                System.Data.DataSet ds = dbo.Select_MODULE_PARAMETER_INSTANCE_By_MOD_PAR_ID(MOD_PAR_ID);
                ModuleParameterInstanceCollection collection = new ModuleParameterInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleParameterInstance obj = new ModuleParameterInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleParameterInstanceCollection GetAll() {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                System.Data.DataSet ds = dbo.MODULE_PARAMETER_INSTANCE_Select_All();
                ModuleParameterInstanceCollection collection = new ModuleParameterInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleParameterInstance obj = new ModuleParameterInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleParameterInstance Load(System.Nullable<System.Guid> MOD_PAR_INS_ID) {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                System.Data.DataSet ds = dbo.MODULE_PARAMETER_INSTANCE_Select_One(MOD_PAR_INS_ID);
                ModuleParameterInstance obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new ModuleParameterInstance();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                System.Data.DataSet ds = dbo.MODULE_PARAMETER_INSTANCE_Select_One(this.ModParInsId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                this.ModParInsId=dbo.MODULE_PARAMETER_INSTANCE_Insert(this.ModuleInstance.ModInsId, this.ModuleParameter.ModParId, this.ModParInsValue);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                dbo.MODULE_PARAMETER_INSTANCE_Delete(this.ModParInsId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            IrisGenerator.Dal.ModuleParameterInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleParameterInstance();
                dbo.MODULE_PARAMETER_INSTANCE_Update(this.ModParInsId, this.ModuleInstance.ModInsId, this.ModuleParameter.ModParId, this.ModParInsValue);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
